package com.aqie.demo.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author aqie
 * @Date 2021/12/21 16:34
 * @desc
 */
public class TimeUtils {
    public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) throws ParseException {
        SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");

        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return true;
        }
        Calendar date = Calendar.getInstance();
        date.setTime(sdf.parse(sdf.format(nowTime)));

        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }

    public static long currentTimeStamp(){
        return  (System.currentTimeMillis());
    }

    public static void main(String[] args) throws ParseException {
        String format = "HH:mm:ss";
        Date nowTime = new Date();
        Date startTime = new SimpleDateFormat(format).parse("14:00:00");
        Date endTime = new SimpleDateFormat(format).parse("23:30:00");
        System.out.println(isEffectiveDate(nowTime, startTime, endTime));
        System.out.println(currentTimeStamp());
    }
}
